package com.example.project.Service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;

@Component
public class CodeUtils {
    @Autowired
    private CodeService codeService;

    public void setCode(String mail,String s){
        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MINUTE, 5);
        String currentTime = sf.format(c.getTime());
        codeService.insertCode(mail,s,currentTime);
    }

    public String VerifyCode(){
        Random r = new Random();
        StringBuilder sb =new StringBuilder();
        for(int i = 0;i < 6;i ++){
            int ran1 = r.nextInt(10);
            sb.append(ran1);
        }
        return sb.toString();
    }
}
